<!DOCTYPE html>
<html lang="zh_CN">
<head>
<#--引入外部文件-->
    <#include "../common/header.ftl">
    <link href="/js/plugins/chosen/component-chosen.css" rel="stylesheet">
    <script src="/js/plugins/chosen/chosen.jquery.js"></script>
</head>
<body>

<div class="container" style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">大家都在看</h1>
                </div>
            </div>

        <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/strategyTravel/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>攻略搜索</label>
                    <select name="strategyId" id="strategyId" class="form-control form-control-chosen"
                            data-placeholder="请选择所属攻略">
                            <option value="-1"></option>
                        <#list strategyIds as s>
                            <option value="${s.id}">${s.title}</option>
                        </#list>
                        <script>
                            $("#strategyId option[value='${(qo.strategyId)!}']").prop("selected", true);
                        </script>
                    </select>
                </div>
                <button id="btn_query" class="btn btn-default">
                    <span class="glyphicon glyphicon-search"></span> 查询
                </button>
                <a href="javascript:" class="btn btn-success inputBtn">
                    <span class="glyphicon glyphicon-plus"></span> 添加关联
                </a>
            </form>
            <label>关联游记 </label>
            <#if travels??>
                <table class="table table-striped table-hover">
                    <tr>
                        <th>编号</th>
                        <th>游记标题</th>
                        <th></th>
                    </tr>
                <#--使用Freemark的指令完成循环迭代-->
                    <#list travels.list as tr>
                        <tr>
                            <td>${tr_index + 1}</td>
                            <td>${tr.title!}</td>
                            <td>
                                <a href="/travelRelease/list.do?travelId=${tr.id}" target="_blank" class="btn btn-info btn-xs">
                                    <span class="glyphicon glyphicon-pencil"></span> 查看游记文章
                                </a>
                                <a href="javascript:void(-1)" class="btn btn-info btn-xs del_Btn" data-jsonstr='${tr.json}'>
                                    <span class="glyphicon glyphicon-pencil"></span> 删除
                                </a>
                            </td>
                        </tr>
                    </#list>
                </table>
            </#if>
        </div>
    </div>
</div>

<#--模态框页面-->
<div id="strategyModal" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">编辑/增加</h4>
            </div>
            <div class="modal-body">
                <form id="editForm" class="form-horizontal" method="post" enctype="multipart/form-data" action="/strategyTravel/insertRelation.do" style="margin: -3px 118px">
                    <div class="form-group">
                        <label class="col-sm-4 control-label">所属攻略</label>
                        <div class="col-sm-6">
                            <select id="strategyTitle" name="strategyId" class="form-control form-control-chosen" data-placeholder="请选择关联的攻略">
                                <#list strategyIds as s>
                                    <option value="${s.id}">${s.title}</option>
                                </#list>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-4 control-label">关联游记</label>
                        <div class="col-sm-6">
                            <select id="travelSelect" name="travelId" class="form-control form-control-chosen" data-placeholder="请选择关联的游记">
                               <#list travel as t>
                                   <option value="${t.id}">${t.title}</option>
                               </#list>
                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <a href="javascript:void(0);" class="btn btn-success" id="saveBtn" aria-hidden="true">保存</a>
                <a href="javascript:void(0);" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {

        $("#query").click(function(){
            $("#searchForm").submit();
        });

        //点击添加按钮0
        $(".inputBtn").click(function(){
            $("#travelId").val( $("#strategySelect option:selected").val());
            $("#strategyId").val($("#strategySelect option:selected").val());
            $("#strategyModal").modal("show");
        });

        $("#editForm").ajaxForm(function(data){
            $.messager.confirm("提示","保存成功",function(){
                window.location.reload();
            });
        });
        //点击保存
        $("#saveBtn").click(function(){
            $("#editForm").submit();
        });

        //点删除击
        $(".del_Btn").click(function () {
            var strategyId = ${(qo.strategyId)!};
            var json=$(this).data("jsonstr");
            $.post("/strategyTravel/deleteRelation.do",{strategyId:strategyId,travelId:json.id},function (data) {
                if(data.success){
                    $.messager.confirm("提示","删除成功",function(){
                        window.location.reload();
                    });
                }
            })
        })
    });
</script>

</body>
</html>